package com.atwulidun.adapter05.springMVC;

public interface HandlerAdapter {
    boolean supports(Object handler);
    void handle(Object handler);
}

// 多种适配器类
class SimpleHandlerAdapter implements HandlerAdapter {
    @Override
    public boolean supports(Object handler) {
        return (handler instanceof SimpleController);
    }

    @Override
    public void handle(Object handler) {
        ((SimpleController)handler).doSimpleHandler();
    }
}

class AnnotationHandlerAdapter implements HandlerAdapter {
    // 先判断传进来的handler是不是对应的controller
    @Override
    public boolean supports(Object handler) {
        return (handler instanceof AnnotationController);
    }
    // 再把handler转成相应的controller
    @Override
    public void handle(Object handler) {
        ((AnnotationController)handler).doAnnotationHandler();
    }
}

class HttpHandlerAdapter implements HandlerAdapter {
    @Override
    public boolean supports(Object handler) {
        return (handler instanceof HttpController);
    }

    @Override
    public void handle(Object handler) {
        ((HttpController)handler).doHttpHandler();
    }
}